We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392660 - git nasm has "error: macro parameter `%+1' is not a condition code" for valid values
Summary: git nasm has "error: macro parameter `%+1' is not a condition code" for valid...
Status: CLOSED FIXED
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.15.xx
Hardware: All All
: Medium severe
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2020-04-16 14:21 PDT by E. C. Masloch
Modified: 2020-05-06 16:01 PDT (History)
4 users (show)

Obtained from: Built from git using configure
Generated by: ---
Bug category:
Observed for: ---
Regression: ---
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2020-04-16 14:21:36 PDT
$ cat test.asm 
 %macro coreloop 1
.count_%+1:
.no_run_before_%+1:
.broken_run_before_%-1:
 %endmacro

label:
coreloop z
coreloop nz
$ nasm -v
NASM version 2.15rc0 compiled on Nov 22 2019
$ nasm test.asm -o test.bin
test.asm:8: error: macro parameter `%+1' is not a condition code
test.asm:2: ... from macro `coreloop' defined here
test.asm:8: error: macro parameter `%+1' is not a condition code
test.asm:3: ... from macro `coreloop' defined here
test.asm:8: error: macro parameter `%-1' is not a condition code
test.asm:4: ... from macro `coreloop' defined here
test.asm:9: error: macro parameter `%+1' is not a condition code
test.asm:2: ... from macro `coreloop' defined here
test.asm:9: error: macro parameter `%+1' is not a condition code
test.asm:3: ... from macro `coreloop' defined here
test.asm:9: error: macro parameter `%-1' is not a condition code
test.asm:4: ... from macro `coreloop' defined here
$ oldnasm -v
NASM version 2.12.02 compiled on Aug 10 2019
$ oldnasm test.asm -o test.bin
$
Comment 1 Chang S. Bae 2020-04-18 16:06:46 PDT
I think there is a glitch checking the parameter number. This change looks to fix:

diff --git a/asm/preproc.c b/asm/preproc.c
index cf770026..fae3b868 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -4837,7 +4837,7 @@ static Token *expand_mmac_params(Token * tline)
                 if (unlikely(*ep))
                     goto invalid;

-                if (n && n < mac->nparam) {
+                if (n && n <= mac->nparam) {
                     n = mmac_rotate(mac, n);
                     tt = mac->params[n];
                 }

For the record, the coresspondent patch for this issue is:

commit de7acc3a46cb3da52464d246b814f8bf059a0360
Author: H. Peter Anvin (Intel) <hpa@zytor.com>
Date:   Mon Aug 19 17:52:55 2019 -0700

    preproc: defer %00, %? and %?? expansion for nested macros, cleanups

    BR 3392603: When doing nested macro definitions, we need %00, %? and
    %?? expansion to be deferred to actual expansion time, just as the
    other parameters.

    Do major cleanups to the mmacro expansion code.

    Reported-by: Alexandre Audibert <alexandre.audibert@outlook.fr>
    Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Comment 2 Chang S. Bae 2020-05-06 16:01:06 PDT
This commit should have resolved the issue:

commit	057b832f45daca2d2260f0e914f565252271b69f
author	Chang S. Bae <chang.seok.bae@intel.com>	
Sat, 18 Apr 2020 23:11:21 +0000 (18 23:11 +0000)
committer	Chang S. Bae <chang.seok.bae@intel.com>	
Tue, 21 Apr 2020 21:28:50 +0000 (21 21:28 +0000)
preproc: Fix the macro-parameter check for conditional code

Mistreating the macro-parameter, just equivalent to the given
argument number, leads to casting an unnecessary error. Fix to
assemble the conditional code correctly.

Fixes: de7acc3a46cb ("preproc: defer %00, %? and %??
expansion for nested macros, cleanups")